﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace Tools {
	[TypeConverter(typeof(ExpandableObjectConverter))]
	public class Vector2 {
		[CategoryAttribute("General"), DescriptionAttribute("X-axis component of Vector2.")]
		public float X { get; set; }
		
		[CategoryAttribute("General"), DescriptionAttribute("Y-axis component of Vector2.")]
		public float Y { get; set; }

		public static Vector2 Zero { get { return new Vector2(); } }
		
		// ----------
		
		public Vector2() {
			X = 0f;
			Y = 0f;
		}

		public Vector2( float value ) {
			X = value;
			Y = value;
		}

		public Vector2( float x, float y ) {
			X = x;
			Y = y;
		}

		// ----------

		public override string ToString() {
			return "(" + X + "," + Y + ")";
		}

		// ----------

		public class ListConverter : TypeConverter {
			public override object ConvertTo( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType ) {
				if( destinationType == typeof(string) ) {
					List<Vector2> list = (List<Vector2>)value;
					return String.Join( ", ", (object[])list.ToArray() );
				}

				return base.ConvertTo( context, culture, value, destinationType );
			}
		}
	}
}
